//
//  ViewController.m
//  MidProject
//
//  Created by itlab on 2020/11/15.
//  Copyright © 2020 itlab. All rights reserved.
//


#import "ViewController.h"


@interface ViewController () {
    NSString *name;
    NSString *password;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    // Do any additional setup after loading the view, typically from a nib.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    UITabBarController  *tabBarVC = [[UITabBarController alloc] init];
    
    PersonViewController *PersonVC =[[PersonViewController alloc]init];
    // 创建按钮
    MMDrawerBarButtonItem * leftDrawerButton = [[MMDrawerBarButtonItem alloc]
                                                initWithTarget:self      action:@selector(leftDrawerButtonPress:)];
    [PersonVC.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
    UINavigationController *PersonNav = [[UINavigationController alloc] initWithRootViewController:PersonVC];
    PersonNav.tabBarItem.title = @"个人主页";
    PersonNav.tabBarItem.image = [[UIImage imageNamed:@"userImg.png"]TransformtoSize:CGSizeMake(28, 28)];
    PersonNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"userImg_selected.png"]TransformtoSize:CGSizeMake(28, 28)];
    
    [tabBarVC addChildViewController:PersonNav];
    
    
    SquareViewController *SquareVC = [[SquareViewController alloc] init];
    [SquareVC.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
    UINavigationController *SquareNav = [[UINavigationController alloc]initWithRootViewController:SquareVC];
    SquareNav.tabBarItem.title = @"广场";
    SquareNav.tabBarItem.image = [[UIImage imageNamed:@"squareImg.png"]TransformtoSize:CGSizeMake(28, 28)];
    SquareNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"squareImg_selected.png"]TransformtoSize:CGSizeMake(28, 28)];
    [tabBarVC addChildViewController:SquareNav];
    
    SettingViewController *SettingVC = [[SettingViewController alloc]init];
    [SettingVC.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES];
    UINavigationController *SettingNav = [[UINavigationController alloc]initWithRootViewController:SettingVC];
    SettingNav.tabBarItem.title = @"设置";
    SettingNav.tabBarItem.image = [[UIImage imageNamed:@"settingImg.png"]TransformtoSize:CGSizeMake(28, 28)];
    SettingNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"settingImg_selected.png"]TransformtoSize:CGSizeMake(28, 28)];
    [tabBarVC addChildViewController:SettingNav];
    
    LeftPageViewController *leftVC = [[LeftPageViewController alloc] init];
    leftVC.view.backgroundColor = [UIColor whiteColor];
    UINavigationController *leftNav = [[UINavigationController alloc]initWithRootViewController:leftVC];
    
    
    self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:tabBarVC leftDrawerViewController:leftNav];
//    self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
//    self.drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
    self.drawerController.maximumLeftDrawerWidth = 200.0;
    leftVC.delegate = self.drawerController;
    
    tabBarVC.tabBar.tintColor = [UIColor orangeColor];
    tabBarVC.selectedIndex = 1;
    self.window.rootViewController = self.drawerController;

    [self.window makeKeyAndVisible];
}

-(void)leftDrawerButtonPress:(id)sender
{
    [self.drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}

@end
